#include "games/lineeditgame.h"

LineEditGame::LineEditGame(QWidget *parent, int difflvl) :
    BaseGame(parent, difflvl)
{
    lineedit = new QLineEdit(this);
    lay->addWidget(lineedit);

    timer = new QTimer(this);
    timer->setInterval(300);

    timer->start();

    connect(timer,SIGNAL(timeout()),this, SLOT(timerTimeout()));

    counter = 0;
    QString char_map = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
    string = "";
    for(int i = 0; i < difficulty_level * 10 + 10; i++) {
        string.append(char_map.at(qrand() % char_map.length()));
    }
}

void LineEditGame::timerTimeout()
{
    int l = lineedit->text().length();
    if( lineedit->text().length() > string.length() || string.left(l) != lineedit->text().left(l) ) {
        lineedit->setText(lineedit->text().left(lineedit->text().length()-1));
    }
}
